import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
/**
 * @description 路由参数说明
 {
  hidden: true // 不在侧边栏出现
  redirect: 'noRedirect' // 面包屑导航中不可被点击
  alwaysShow: true // children为1时默认不显示父级菜单，true则显示
  name: 'router-name' // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
  meta: {
    title: 'title' // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'el-icon-x' // 设置该路由的图标，el-icon-x element-ui 的 icon
    breadcrumb: false //  如果设置为false，则不会在breadcrumb面包屑中显示(默认 true)
    noCache: true // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    affix: true // 若果设置为true，它则会固定在tags-view中(默认 false)
    activeMenu: '/article/list' // 高亮相对应的侧边栏。
    protected: false //  该路由是否受保护，默认值为false即不受保护
    受保护的路由地址是登录成功后才能访问，每次进入会检测是否获取了用户信息
    不受保护的路由地址会直接打开。一个使用场景是在登录页面，是需要设置为不受保护的例如
    permission
 }
 */
import enterprise from '@/router/modules/enterprise'
import marketing from '@/router/modules/marketing'
import approve from '@/router/modules/approve'
import order from '@/router/modules/order'
import finance from '@/router/modules/finance'
import user from '@/router/modules/user'
import content from '@/router/modules/content'
import service from '@/router/modules/service'
import system from '@/router/modules/system'
import Layout from '@/layout/index.vue'

export const asyncRoutes = [
  ...enterprise,
  ...marketing,
  ...approve,
  ...order,
  ...finance,
  ...user,
  ...content,
  ...service,
  ...system
]
export const constantRoutes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        name: 'DataCenter',
        component: () => import('@/views/dataCenter/index.vue'),
        meta: { title: '数据看板', icon: 'icon-shujukanban' }
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    meta: { title: '登录' },
    hidden: true
  }, {
    path: '/openLogin',
    component: () => import('@/views/login/openLogin.vue'),
    meta: { title: '登录' },
    hidden: true
  }, {
    path: '/401',
    component: () => import('@/views/400/401.vue'),
    meta: { title: '401' },
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/400/404.vue'),
    meta: { title: '404' },
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
